package com.zjuee.core.translation.service;


import com.zjuee.core.translation.factory.ServiceStrategyFactory;
import com.zjuee.core.translation.handledata.DataHandlerStrategy;
import com.zjuee.core.translation.handledata.GetServiceStrategy;
import com.zjuee.core.translation.utils.SpringContextUtil;
import org.springframework.stereotype.Component;

/**
 * @author wu liang
 * @since 2020/10/10 13:59
 */
@Component
public class TranslateData {

    /**
     * 翻译数据
     * @param obj 需要翻译的数据
     * @param dataType 实现bean - 参考CorpInfoHandle实现
     * @param str 需要翻译字段对应redis中的key - 参考DictionaryType，RedisCacheType类
     * @return Object
     */
    public Object translateData(Object obj, String dataType,  String... str){
        //获取并设置策略
//        DataHandleStrategyFactory dataHandleStrategyFactory = new DataHandleStrategyFactory();
//        DataHandlerStrategy dataHandlerStrategy = dataHandleStrategyFactory.getDataHandleStrategy(dataType);
        DataHandlerStrategy dataHandlerStrategy = (DataHandlerStrategy) SpringContextUtil.getBean(dataType);
        Object o = dataHandlerStrategy.handleListData(obj, str);
        return o;
    }

    public Object BusinessData(Object obj, String dataType,  String... str){
        //获取并设置策略
        GetServiceStrategy strategy = ServiceStrategyFactory.getServiceStrategyImpl(dataType);
        return strategy.getObject(obj, str);
    }
}
